package com.jymj.service.impl;

import com.jymj.dao.RtExpectDao;
import com.jymj.entity.RtExpect;
import com.jymj.entity.view.RtExpectTask;
import com.jymj.service.RtExpectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RtExpectServiceImpl implements RtExpectService {

    @Autowired
    private RtExpectDao rtExpectDao;

    @Override
    public int importdb(RtExpect rtExpect) {
        return rtExpectDao.saveData(rtExpect);
    }

    @Override
    public int importSome(List<RtExpect> rtExpectList) {
        return rtExpectDao.insertSome(rtExpectList);
    }

    @Override
    public List<RtExpect> selectByPjId(Integer pjid) {
        return rtExpectDao.selectByPjid(pjid);
    }

    @Override
    public void delByPjid(Integer pjid) {
        rtExpectDao.delByPjid(pjid);//执行删除操作
    }

    @Override
    public void save(RtExpect rtExpect) {
        rtExpectDao.save(rtExpect);
    }

    @Override
    public void update(RtExpect rtExpect) {
        rtExpectDao.update(rtExpect);
    }

    @Override
    public void delete(Integer id) {
        rtExpectDao.delete(id);
    }

    @Override
    public void updateParentCost(RtExpect rtExpect) {
        Map map = new HashMap();
        map.put("taskid", rtExpect.getTaskid());
        map.put("pjid", rtExpect.getPjid());
        RtExpectTask rtExpectTask = rtExpectDao.queryObject1(map);
        if (rtExpectTask == null || rtExpectTask.getPtfatherid() == 0) {
            return;
        }
        if (rtExpectTask.getPtfatherid() != null) {
            Map map1 = new HashMap();
            map1.put("taskid", rtExpectTask.getPtfatherid());
            map1.put("pjid", rtExpectTask.getPtpjid());
            RtExpectTask fatherRtExpect = rtExpectDao.queryObjectParent(map1);
            if (fatherRtExpect != null) {
                RtExpect RtExpect1 = new RtExpect();
                RtExpect1.setPjid(fatherRtExpect.getPtpjid());
                RtExpect1.setTaskid(fatherRtExpect.getPttaskid());
                if (fatherRtExpect.getId() == null) {
                    this.save(RtExpect1);
                }
                rtExpectDao.updateParentCost(RtExpect1);
                updateParentCost(RtExpect1);
            }
        }
    }

    @Override
    public List<RtExpectTask> queryList(Map<String, Object> map) {
        return rtExpectDao.queryList(map);
    }

    @Override
    public RtExpect queryObject(Integer id) {
        return rtExpectDao.queryObject(id);
    }

    @Override
    public List<RtExpect> queryAll(Integer pjid) {
        return rtExpectDao.queryAll(pjid);
    }

}
